<?php
/**
 * @link https://ym2.cleverstone.top
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace builder\form\util\control;

/**
 * 评分控件
 * @author Clevstn
 * @since ym2.0
 */
class Star extends Control
{
    /**
     * @var array
     */
    private $_options = [
        'control' => 'star',
        'label' => '',
        'default' => 0,
        'required' => false,
        'comment' => '',
        'layout' => 12,
        'style' => '',
        'class' => '',
        'attribute' => '',
        // layui rate组件配置
        'config' => [
            //'setText' => ['无', '非常差', '很差', '一般', '不错', '非常棒'], //这里`setText`不是函数
        ],
    ];

    /**
     * layui rate组件配置
     * @param string $key
     * @param mixed $value
     * @return $this
     * @see https://layui.dev/docs/2/rate/#options
     * 支持 length/half/theme/text/readonly/setText
     */
    public function pluginConfig($key, $value)
    {
        $this->_options['config'][$key] = $value;
        return $this;
    }

    /**
     * 控件标签
     * @param string $label
     * @return $this
     */
    public function label($label)
    {
        $this->_options['label'] = (string)$label;
        return $this;
    }

    /**
     * 默认值
     * @param string $default
     * @return $this
     */
    public function defaultValue($default)
    {
        $this->_options['default'] = (string)$default;
        return $this;
    }

    /**
     * 是否必填
     * @param bool $required
     * @return $this
     */
    public function required($required = true)
    {
        $this->_options['required'] = (boolean)$required;
        return $this;
    }

    /**
     * 字段注释
     * @param string $comment
     * @return $this
     */
    public function comment($comment)
    {
        $this->_options['comment'] = (string)$comment;
        return $this;
    }

    /**
     * 布局，1-12
     * @param int $layout
     * @return $this
     */
    public function layout($layout)
    {
        $this->_options['layout'] = (int)$layout;
        return $this;
    }

    /**
     * CSS样式
     * @param array|string $style
     * @return $this
     */
    public function style($style)
    {
        $this->formatStyle($style);
        $this->_options['style'] = $style;

        return $this;
    }

    /**
     * UI
     * @param array|string $class
     * @return $this
     */
    public function uiClass($class)
    {
        $this->formatUiClass($class);
        $this->_options['class'] = $class;

        return $this;
    }

    /**
     * HTML属性
     * @param array|string $attribute
     * @return $this
     */
    public function attribute($attribute)
    {
        $this->formatHtmlAttribute($attribute);
        $this->_options['attribute'] = $attribute;

        return $this;
    }

    /**
     * @return array
     */
    public function _toArray()
    {
        return $this->_options;
    }
}